﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.DirectX.Direct3D;
using Microsoft.DirectX;
using System.Drawing;

namespace DX.engine.camera
{
    public class Camera : ICameraManager
    {

        public void PositionCamera(Microsoft.DirectX.Direct3D.Device device)
        {
            EngineSettings es = Engine.GetSettings();
            bool EnableLighting = es.FetchBoolSetting("EnableLighting");
            bool EnableCulling = es.FetchBoolSetting("EnableCulling");
            bool EnableWireframe = es.FetchBoolSetting("EnableWireframe");
            float Width = es.FetchFloatSetting("Width");
            float Height = es.FetchFloatSetting("Height");

            device.VertexFormat = CustomVertex.PositionColored.Format;
            device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, Width / Height, 1f, 500f);
            device.Transform.View = Matrix.LookAtLH(new Vector3(0, -40, 100), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
            device.RenderState.Lighting = EnableLighting;
            if (EnableLighting)
            {
                //Define our lights
                device.Lights[0].Type = LightType.Directional;
                device.Lights[0].Diffuse = Color.White;
                device.Lights[0].Direction = new Vector3(-0.5f, 0, -1f);
                device.Lights[0].Enabled = true;
            }
            if (!EnableCulling)
                device.RenderState.CullMode = Cull.None;
            else
                device.RenderState.CullMode = Cull.CounterClockwise;
            if (EnableWireframe)
                device.RenderState.FillMode = FillMode.WireFrame;
            else
                device.RenderState.FillMode = FillMode.Solid;
        }
    }
}
